﻿// ----------------------------------------------------------------------------
// Copyright (C) 2009 XXXXX
// 版权所有。 
//
// 文件名：DataAccessManager.cs
// 文件功能描述：DataAccessManager Class 基于DataSet的业务逻辑基类，基于POCO的基类请查询
// Husb 写的 DomainObjectBase 类
// 
// 创建标识：2009-3-9 9:31:44 husb    Original Version
//
// 修改标识：2009-3-9
// 修改描述：
//
//
// 注：2007-05-16 husb 此类由于没有优化，里面有一些重复的代码，且功能不完善，已经过时，请使用husb关于此功能的新类
// ----------------------------------------------------------------------------


using System;
using System.Collections.Generic;

using System.Text;
using Husb.DataUtil;
using System.Data;

namespace Husb.Data
{
    public class DataAccessManager<S, T, R, TDataAccessAdapter> : IDataAccessManager<S, T, R>
        where S : DataSet, new()
        where T : DataTable, new()
        where R : DataRow
        where TDataAccessAdapter : DataAccessAdapter<S, T, R>, new()
    {
        private static TDataAccessAdapter adapter = null;
        public static TDataAccessAdapter Adapter
        {
            get
            {
                if (adapter == null)
                {
                    adapter = new TDataAccessAdapter();
                }
                return adapter;
            }
        }


        #region GetAll & GetTable & GetDataSet
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static T GetAll()
        {
            return GetAll(true, true, null);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="enableCache"></param>
        /// <returns></returns>
        public static T GetAll(bool enableCache)
        {
            return GetAll(true, enableCache, null);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="isStoredProc"></param>
        /// <param name="enableCache"></param>
        /// <returns></returns>
        public static T GetAll(bool isStoredProc, bool enableCache)
        {
            return GetAll(isStoredProc, enableCache, null);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="isStoredProc"></param>
        /// <param name="enableCache"></param>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        public static T GetAll(bool isStoredProc, bool enableCache, string cacheKey)
        {
            return Adapter.GetAll(isStoredProc, enableCache, cacheKey);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static T GetTable(string commandText, List<DatabaseParameter> parameters, bool isStoredProc)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.GetTable(commandText, parameters, isStoredProc);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="enableCache"></param>
        /// <param name="cacheKey"></param>
        /// <returns></returns>
        public static S GetDataSet(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc, bool enableCache, string cacheKey)
        {
            return Adapter.GetDataSet(commandText, parameters, isStoredProc, enableCache, cacheKey);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="enableCache"></param>
        /// <returns></returns>
        public static S GetDataSet(string commandText, IEnumerable<DatabaseParameter> parameters, bool enableCache)
        {
            return Adapter.GetDataSet(commandText, parameters, true, enableCache, null);
        }
        #endregion

        #region Fill
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="dataSet"></param>
        /// <param name="tableName"></param>
        /// <param name="enableCache"></param>
        /// <param name="cacheKey"></param>
        public static void Fill(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc, S dataSet, string tableName, bool enableCache, string cacheKey)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            Adapter.Fill(commandText, parameters, isStoredProc, dataSet, tableName, enableCache, cacheKey);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="dataSet"></param>
        /// <param name="enableCache"></param>
        /// <param name="cacheKey"></param>
        public static void Fill(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc, S dataSet, bool enableCache, string cacheKey)
        {
            Adapter.Fill(commandText, parameters, isStoredProc, dataSet, dataSet.Tables[0].TableName, enableCache, cacheKey);
        }

        public static void Fill(string commandText, IEnumerable<DatabaseParameter> parameters, S dataSet, bool enableCache)
        {
            Adapter.Fill(commandText, parameters, true, dataSet, dataSet.Tables[0].TableName, enableCache, null);
        }

        public static void Fill(string commandText, List<DatabaseParameter> parameters, S dataSet, string[] tableNames, bool enableCache)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            Adapter.Fill(commandText, parameters, true, dataSet, tableNames, enableCache, null);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="tableName"></param>
        public static void Fill(S ds, string tableName)
        {
            Adapter.Fill(ds, tableName);
        }

        public static void Fill(S ds, bool enableCache)
        {
            Adapter.Fill(ds, enableCache);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ds"></param>
        public static void Fill(S ds)
        {
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            Adapter.Fill(ds);
            //throw new Exception("The method or operation is not implemented.");
        }
        #endregion

        #region Update
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSet"></param>
        /// <returns></returns>
        public static int Update(DataSet dataSet)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.Update(dataSet);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataSet"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="removeCache"></param>
        /// <param name="cacheItemKeys"></param>
        /// <returns></returns>
        public static int Update(DataSet dataSet, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.Update(dataSet, isStoredProc, removeCache, cacheItemKeys);
        }

        public static int Update(DataSet dataSet, bool removeCache, string[] cacheItemKeys)
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.Update(dataSet, true, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter"></typeparam>
        /// <typeparam name="OS"></typeparam>
        /// <typeparam name="OT"></typeparam>
        /// <typeparam name="OR"></typeparam>
        /// <param name="dataSet"></param>
        /// <param name="detailDataSet"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="removeCache"></param>
        /// <param name="cacheItemKeys"></param>
        /// <returns></returns>
        public static bool UpdateSelfAndDetail<TAdapter, OS, OT, OR>(DataSet dataSet, DataSet detailDataSet, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
            where TAdapter : DataAccessAdapter<OS, OT, OR>, new()
            where OS : DataSet, new()
            where OT : DataTable, new()
            where OR : DataRow
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.UpdateSelfAndDetail<TAdapter, OS, OT, OR>(dataSet, detailDataSet, isStoredProc, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter"></typeparam>
        /// <typeparam name="OS"></typeparam>
        /// <typeparam name="OT"></typeparam>
        /// <typeparam name="OR"></typeparam>
        /// <param name="dataSet"></param>
        /// <param name="detailDataSet"></param>
        /// <returns></returns>
        public static bool UpdateSelfAndDetail<TAdapter, OS, OT, OR>(DataSet dataSet, DataSet detailDataSet)
            where TAdapter : DataAccessAdapter<OS, OT, OR>, new()
            where OS : DataSet, new()
            where OT : DataTable, new()
            where OR : DataRow
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.UpdateSelfAndDetail<TAdapter, OS, OT, OR>(dataSet, detailDataSet, true, false, null);
        }

        public static bool UpdateSelfAndMaster<TAdapter, OS, OT, OR>(DataSet dataSet, DataSet masterDataSet, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
            where TAdapter : DataAccessAdapter<OS, OT, OR>, new()
            where OS : DataSet, new()
            where OT : DataTable, new()
            where OR : DataRow
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.UpdateSelfAndMaster<TAdapter, OS, OT, OR>(dataSet, masterDataSet, isStoredProc, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter"></typeparam>
        /// <typeparam name="OS"></typeparam>
        /// <typeparam name="OT"></typeparam>
        /// <typeparam name="OR"></typeparam>
        /// <param name="dataSet"></param>
        /// <param name="masterDataSet"></param>
        /// <returns></returns>
        public static bool UpdateSelfAndMaster<TAdapter, OS, OT, OR>(DataSet dataSet, DataSet masterDataSet)
            where TAdapter : DataAccessAdapter<OS, OT, OR>, new()
            where OS : DataSet, new()
            where OT : DataTable, new()
            where OR : DataRow
        {
            //throw new Exception("The method or operation is not implemented.");
            //TDataAccessAdapter adapter = new TDataAccessAdapter();
            return Adapter.UpdateSelfAndMaster<TAdapter, OS, OT, OR>(dataSet, masterDataSet, true, false, null);
        }
        public static bool UpdateSelfAndDetail<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(DataSet dataSet, DataSet detailDataSet1, DataSet detailDataSet2, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.UpdateSelfAndDetail<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(dataSet, detailDataSet1, detailDataSet2, isStoredProc, removeCache, cacheItemKeys);
        }



        #endregion

        #region ExecuteNonQuery
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc)
        {
            return Adapter.ExecuteNonQuery(commandText, parameters, isStoredProc);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string commandText, IEnumerable<DatabaseParameter> parameters)
        {
            return Adapter.ExecuteNonQuery(commandText, parameters, true);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText"></param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string commandText)
        {
            return Adapter.ExecuteNonQuery(commandText, new List<DatabaseParameter>(), true);
        }

        public static int ExecuteNonQuery(string commandText, PopulateParameters populateParametersHandler, bool isStoredProc)
        {
            return Adapter.ExecuteNonQuery(commandText, populateParametersHandler, isStoredProc);
        }

        public static int ExecuteNonQuery(string commandText, PopulateParameters populateParametersHandler)
        {
            return Adapter.ExecuteNonQuery(commandText, populateParametersHandler, true);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText1"></param>
        /// <param name="populateParametersHandler1"></param>
        /// <param name="commandText2"></param>
        /// <param name="populateParametersHandler2"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="removeCache"></param>
        /// <param name="cacheItemKeys"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery(string commandText1, PopulateParameters populateParametersHandler1, string commandText2, PopulateParameters populateParametersHandler2, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
        {
            return Adapter.ExecuteNonQuery(commandText1, populateParametersHandler1, commandText2, populateParametersHandler2, isStoredProc, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText1"></param>
        /// <param name="populateParametersHandler1"></param>
        /// <param name="commandText2"></param>
        /// <param name="populateParametersHandler2"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery(string commandText1, PopulateParameters populateParametersHandler1, string commandText2, PopulateParameters populateParametersHandler2, bool isStoredProc)
        {
            string[] cacheItemKeys = new string[2];
            cacheItemKeys[0] = commandText1;
            cacheItemKeys[1] = commandText2;
            return Adapter.ExecuteNonQuery(commandText1, populateParametersHandler1, commandText2, populateParametersHandler2, isStoredProc, true, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText1"></param>
        /// <param name="populateParametersHandler1"></param>
        /// <param name="commandText2"></param>
        /// <param name="populateParametersHandler2"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery(string commandText1, PopulateParameters populateParametersHandler1, string commandText2, PopulateParameters populateParametersHandler2)
        {
            string[] cacheItemKeys = new string[2];
            cacheItemKeys[0] = commandText1;
            cacheItemKeys[1] = commandText2;
            return Adapter.ExecuteNonQuery(commandText1, populateParametersHandler1, commandText2, populateParametersHandler2, true, true, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText1"></param>
        /// <param name="parameters1"></param>
        /// <param name="commandText2"></param>
        /// <param name="parameters2"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="removeCache"></param>
        /// <param name="cacheItemKeys"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery(string commandText1, IEnumerable<DatabaseParameter> parameters1, string commandText2, IEnumerable<DatabaseParameter> parameters2, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
        {
            return Adapter.ExecuteNonQuery(commandText1, parameters1, commandText2, parameters2, isStoredProc, removeCache, cacheItemKeys);
        }

        public static bool ExecuteNonQuery(string commandText1, IEnumerable<DatabaseParameter> parameters1, string commandText2, IEnumerable<DatabaseParameter> parameters2, bool isStoredProc)
        {
            string[] cacheItemKeys = new string[2];
            cacheItemKeys[0] = commandText1;
            cacheItemKeys[1] = commandText2;
            return Adapter.ExecuteNonQuery(commandText1, parameters1, commandText2, parameters2, isStoredProc, true, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commandText1"></param>
        /// <param name="parameters1"></param>
        /// <param name="commandText2"></param>
        /// <param name="parameters2"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery(string commandText1, IEnumerable<DatabaseParameter> parameters1, string commandText2, IEnumerable<DatabaseParameter> parameters2)
        {
            string[] cacheItemKeys = new string[2];
            cacheItemKeys[0] = commandText1;
            cacheItemKeys[1] = commandText2;
            return Adapter.ExecuteNonQuery(commandText1, parameters1, commandText2, parameters2, true, true, cacheItemKeys);
        }

        public static bool ExecuteNonQuery(string commandText1, string commandText2)
        {
            string[] cacheItemKeys = new string[2];
            cacheItemKeys[0] = commandText1;
            cacheItemKeys[1] = commandText2;
            return Adapter.ExecuteNonQuery(commandText1, new List<DatabaseParameter>(), commandText2, new List<DatabaseParameter>(), true, true, cacheItemKeys);
        }

        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, PopulateParameters populateParametersHandler, DataSet detailDataSet1, DataSet detailDataSet2, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, populateParametersHandler, detailDataSet1, detailDataSet2, isStoredProc, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter1"></typeparam>
        /// <typeparam name="OS1"></typeparam>
        /// <typeparam name="OT1"></typeparam>
        /// <typeparam name="OR1"></typeparam>
        /// <typeparam name="TAdapter2"></typeparam>
        /// <typeparam name="OS2"></typeparam>
        /// <typeparam name="OT2"></typeparam>
        /// <typeparam name="OR2"></typeparam>
        /// <param name="commandText"></param>
        /// <param name="populateParametersHandler"></param>
        /// <param name="detailDataSet1"></param>
        /// <param name="detailDataSet2"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, PopulateParameters populateParametersHandler, DataSet detailDataSet1, DataSet detailDataSet2, bool isStoredProc)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, populateParametersHandler, detailDataSet1, detailDataSet2, isStoredProc, true, null);
        }

        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, PopulateParameters populateParametersHandler, DataSet detailDataSet1, DataSet detailDataSet2)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, populateParametersHandler, detailDataSet1, detailDataSet2, true, true, null);
        }

        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, IEnumerable<DatabaseParameter> parameters, DataSet detailDataSet1, DataSet detailDataSet2, bool isStoredProc, bool removeCache, string[] cacheItemKeys)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, parameters, detailDataSet1, detailDataSet2, isStoredProc, removeCache, cacheItemKeys);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter1"></typeparam>
        /// <typeparam name="OS1"></typeparam>
        /// <typeparam name="OT1"></typeparam>
        /// <typeparam name="OR1"></typeparam>
        /// <typeparam name="TAdapter2"></typeparam>
        /// <typeparam name="OS2"></typeparam>
        /// <typeparam name="OT2"></typeparam>
        /// <typeparam name="OR2"></typeparam>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="detailDataSet1"></param>
        /// <param name="detailDataSet2"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, IEnumerable<DatabaseParameter> parameters, DataSet detailDataSet1, DataSet detailDataSet2, bool isStoredProc)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, parameters, detailDataSet1, detailDataSet2, isStoredProc, true, null);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TAdapter1"></typeparam>
        /// <typeparam name="OS1"></typeparam>
        /// <typeparam name="OT1"></typeparam>
        /// <typeparam name="OR1"></typeparam>
        /// <typeparam name="TAdapter2"></typeparam>
        /// <typeparam name="OS2"></typeparam>
        /// <typeparam name="OT2"></typeparam>
        /// <typeparam name="OR2"></typeparam>
        /// <param name="commandText"></param>
        /// <param name="parameters"></param>
        /// <param name="detailDataSet1"></param>
        /// <param name="detailDataSet2"></param>
        /// <returns></returns>
        public static bool ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(string commandText, IEnumerable<DatabaseParameter> parameters, DataSet detailDataSet1, DataSet detailDataSet2)
            where TAdapter1 : DataAccessAdapter<OS1, OT1, OR1>, new()
            where TAdapter2 : DataAccessAdapter<OS2, OT2, OR2>, new()
            where OS1 : DataSet, new()
            where OT1 : DataTable, new()
            where OR1 : DataRow
            where OS2 : DataSet, new()
            where OT2 : DataTable, new()
            where OR2 : DataRow
        {
            return Adapter.ExecuteNonQuery<TAdapter1, OS1, OT1, OR1, TAdapter2, OS2, OT2, OR2>(commandText, parameters, detailDataSet1, detailDataSet2, true, true, null);
        }

        #endregion

        #region paging
        /// <summary>
        /// 
        /// </summary>
        /// <param name="whereClause"></param>
        /// <param name="orderBy"></param>
        /// <param name="hideDeleted"></param>
        /// <param name="sortExpression"></param>
        /// <param name="maximumRows"></param>
        /// <param name="startRowIndex"></param>
        /// <param name="isStoredProc"></param>
        /// <param name="enableCache"></param>
        /// <returns></returns>
        public static T GetPaged(string whereClause, string orderBy, bool hideDeleted, string sortExpression, int maximumRows, int startRowIndex, bool isStoredProc, bool enableCache)
        {
            return Adapter.GetPaged(startRowIndex, maximumRows, sortExpression, whereClause, orderBy, hideDeleted, isStoredProc, enableCache);
        }
        // whereClause, sortExpression, maximumRows, startRowIndex
        public static T GetPaged(string whereClause, string orderBy, bool hideDeleted, string sortExpression, int maximumRows, int startRowIndex)
        {
            return GetPaged(whereClause, orderBy, hideDeleted, sortExpression, maximumRows, startRowIndex, true, false);
        }

        public static T GetPaged(string whereClause, string orderBy, string sortExpression, int maximumRows, int startRowIndex)
        {
            return GetPaged(whereClause, orderBy, true, sortExpression, maximumRows, startRowIndex, true, false);
        }

        public static T GetPaged(string whereClause, bool hideDeleted, string sortExpression, int maximumRows, int startRowIndex)
        {
            return GetPaged(whereClause, null, hideDeleted, sortExpression, maximumRows, startRowIndex);
        }

        public static T GetPaged(string whereClause, string sortExpression, int maximumRows, int startRowIndex)
        {
            return GetPaged(whereClause, true, sortExpression, maximumRows, startRowIndex);
        }

        //public static T GetPaged(string whereClause, string orderBy, int maximumRows, int startRowIndex)
        //{
        //    return GetPaged(whereClause, orderBy, null, maximumRows, startRowIndex);
        //}

        public static T GetPaged(string whereClause, int maximumRows, int startRowIndex)
        {
            return GetPaged(whereClause, null, true, null, maximumRows, startRowIndex);
        }

        public static T GetPaged(int maximumRows, int startRowIndex)
        {
            return GetPaged(null, maximumRows, startRowIndex);
        }

        //whereClause, sortExpression

        public static int GetCount(string whereClause, bool hideDeleted, bool enableCache)
        {
            return Adapter.GetCount(whereClause, hideDeleted, enableCache);
        }

        public static int GetCount(string whereClause, bool hideDeleted, string orderBy)
        {
            return Adapter.GetCount(whereClause, hideDeleted, false);
        }

        public static int GetCount(string whereClause, bool hideDeleted)
        {
            return Adapter.GetCount(whereClause, hideDeleted, false);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="whereClause"></param>
        /// <returns></returns>
        public static int GetCount(string whereClause)
        {
            return Adapter.GetCount(whereClause, true, false);
        }
        
        //public static int GetCount(int startRowIndex, int maximumRows, string whereClause, string sortExpression)
        //{
        //    TDomainObjectDao domainObjectDao = new TDomainObjectDao();
        //    return domainObjectDao.GetCount(whereClause);
        //}

        public static int GetCount()
        {
            return GetCount(null, false);
        }
        #endregion

        #region IDataAccessManager<S,T> Members

        T IDataAccessManager<S, T, R>.GetTable(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IDataAccessManager<S, T, R>.Fill(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc, S dataSet, string[] tableNames)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IDataAccessManager<S, T, R>.Fill(string commandText, IEnumerable<DatabaseParameter> parameters, bool isStoredProc, S dataSet, string tableName)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        void IDataAccessManager<S, T, R>.Fill(S ds)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        int IDataAccessManager<S, T, R>.Update(S dataSet)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        T IDataAccessManager<S, T, R>.GetAll()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region GetById

        public static R GetById(string id, bool isStoredProc)
        {
            return Adapter.GetById(id, isStoredProc);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static R GetById(Guid id)
        {
            return Adapter.GetById(id, true);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="isStoredProc"></param>
        /// <returns></returns>
        public static R GetById(Guid id, bool isStoredProc)
        {
            return Adapter.GetById(id, isStoredProc);
        }

        public static R GetById(byte[] id, bool isStoredProc)
        {
            if (id == null)
                return null;
            if (id.Length == 16)
            {
                Guid identity = new Guid(id);
                return Adapter.GetById(identity, isStoredProc);
            }
            return null;
        }

        public static R GetById(int entityId)
        {
            return Adapter.GetById(entityId, true);
        }

        public static R GetById(int entityId, bool isStoredProc)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetById(entityId, isStoredProc);
        }

        public static R GetByIdFromCache(Guid id)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetByIdFromCache(id);
        }

        public static R GetByIdFromCache(Guid id, bool isStoredProc)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetByIdFromCache(id, isStoredProc);
        }

        public static R GetByIdFromCache(byte[] id, bool isStoredProc)
        {
            //throw new Exception("The method or operation is not implemented.");
            if (id == null)
                return null;
            if (id.Length == 16)
            {
                Guid identity = new Guid(id);
                return Adapter.GetByIdFromCache(identity, isStoredProc);
            }
            return null;
        }

        public static R GetByIdFromCache(string id)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetByIdFromCache(id);
        }

        public static R GetByIdFromCache(string id, bool isStoredProc)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetByIdFromCache(id, isStoredProc);
        }

        #endregion

        #region GetById : IDataAccessManager<S,T,R> Members


        R IDataAccessManager<S, T, R>.GetById(Guid id)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetById(id, true);
        }

        R IDataAccessManager<S, T, R>.GetByIdFromCache(Guid id)
        {
            //throw new Exception("The method or operation is not implemented.");
            return Adapter.GetByIdFromCache(id);
        }

        #endregion

        #region Get
        //public static T GetByName(string name)
        //{
        //    return Adapter.GetByName(name);
        //}
        public static T GetByName(string name)
        {
            return GetByName(name, true, true, false);
        }
        public static T GetByName(string name, bool exactMatch)
        {
            return GetByName(name, exactMatch, true, false);
        }

        public static T GetByName(string name, bool exactMatch, bool isStoredProc, bool enableCache)
        {
            return Adapter.GetByName(name, exactMatch, isStoredProc, enableCache);
        }

        public static R[] GetByNameFromCache(string name)
        {
            return Adapter.GetByNameFromCache(name);
        }

        public static R GetByNameExactMatchFromCache(string name)
        {
            return Adapter.GetByNameExactMatchFromCache(name);
        }

        public static T GetByMasterId(Guid id)
        {
            return Adapter.GetByMasterId(id);
        }

        public static T GetByMasterId(string masterId)
        {
            return Adapter.GetByMasterId(new Guid(masterId));
        }

        public static T GetByMasterId(Guid id, string masterFieldName)
        {
            return Adapter.GetByMasterId(id, masterFieldName);
        }

        public static T Find(string whereClause, string orderByExpression, bool hideDeleted, bool isStoredProc, bool enableCache)
        {
            return Adapter.Find(whereClause, orderByExpression, hideDeleted, isStoredProc, enableCache);
        }

        public static T Find(string whereClause, string orderByExpression, bool isStoredProc, bool enableCache)
        {
            return Find(whereClause, orderByExpression, false, isStoredProc, enableCache);
            //return Adapter.Find( whereClause,  orderByExpression,  isStoredProc,  enableCache);
        }

        public static T Find(string whereClause, string orderByExpression)
        {
            return Find(whereClause, orderByExpression, true, false);
        }

        public static T Find(string whereClause)
        {
            return Find(whereClause, null, true, false);
        }

        public static T Find(string whereClause, bool hideDeleted, bool isStoredProc)
        {
            return Find(whereClause, null, hideDeleted, isStoredProc, false);
        }

        #endregion

        #region Delete : IDataAccessManager<S,T,R> Members
        int IDataAccessManager<S, T, R>.Delete(Guid id, bool logical)
        {
            return Adapter.Delete(id, logical);
        }

        int IDataAccessManager<S, T, R>.Delete(Guid id)
        {
            return Adapter.Delete(id);
        }

        public static int DeleteById(Guid id)
        {
            return Adapter.Delete(id, false);
        }

        public static int DeleteById(string id, bool isStoredProc, bool removeCache, bool logical)
        {
            return Adapter.Delete(id, isStoredProc, removeCache, new string[] { Adapter.TableName }, logical);
        }

        public static int DeleteById(int id, bool isStoredProc)
        {
            return Adapter.Delete(id, isStoredProc, true, new string[] { Adapter.TableName }, false);
        }

        public static int DeleteById(Guid id, bool isStoredProc, bool logical)
        {
            return Adapter.Delete(id, isStoredProc, false, new string[] { logical ? Adapter.LogicalDeleteStoredProc : Adapter.DeleteStoredProc }, logical);
        }

        public static int Delete(System.Byte[] id, bool isStoredProc, bool logical)
        {
            if (id == null)
                return 0;
            if (id.Length == 16)
            {
                Guid identity = new Guid(id);
                return Adapter.Delete(identity, isStoredProc, false, new string[] { logical ? Adapter.LogicalDeleteStoredProc : Adapter.DeleteStoredProc }, logical);
            }

            return 0;
        }

        //public static int DeleteById(Guid id, bool logical)
        //{
        //    return Adapter.Delete(id, logical);
        //}

        public static int Delete(string commandText, string criteria, bool isStoredProc)
        {
            return Adapter.Delete(commandText, criteria, isStoredProc);
        }

        #endregion

    }
}
